package com.zhang.springcloud.controller;

import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import com.zhang.springcloud.service.PaymentHystrixService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
//全局服务降级
//@DefaultProperties(defaultFallback = "payment1")
public class OrderController {
    @Autowired
    PaymentHystrixService paymentHystrixService;
    @GetMapping("/payment/hystrix/order/{id}")
    public String get(@PathVariable("id") Integer id){
        return paymentHystrixService.paymentTest1(id);
    }

    @RequestMapping("/payment/hystrix/timeout/order/{id}")
/*    @HystrixCommand(fallbackMethod = "payment",commandProperties = {
            @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "2000")})*/
   // @HystrixCommand
    public String getTimeOut(@PathVariable("id") Integer id){
        int i=1/0;
        return paymentHystrixService.paymentTimeout(id);
    }
    public String payment(@PathVariable("id") Integer id){
        return  "我是80，对方忙请求超时"+id;
    }
    public String payment1(@PathVariable("id") Integer id){
        return  "我是80，对方忙请求超时1"+id;
    }
}
